/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author user0
 */
@Entity
@Table(name = "STORE")
@XmlRootElement
@NamedQueries({
	@NamedQuery(name = "Store.findAll", query = "SELECT s FROM Store s"),
	@NamedQuery(name = "Store.findByStoreId", query = "SELECT s FROM Store s WHERE s.storeId = :storeId"),
	@NamedQuery(name = "Store.findByName", query = "SELECT s FROM Store s WHERE s.name = :name"),
	@NamedQuery(name = "Store.findByAddress", query = "SELECT s FROM Store s WHERE s.address = :address")})
public class Store implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        @Column(name = "STORE_ID")
	private Integer storeId;
	@Basic(optional = false)
        @Column(name = "NAME")
	private String name;
	@Basic(optional = false)
        @Column(name = "ADDRESS")
	private String address;
	@ManyToMany(mappedBy = "storeList")
	private List<Product> productList;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "store")
	private List<Purchase> purchaseList;

	public Store() {
	}

	public Store(Integer storeId) {
		this.storeId = storeId;
	}

	public Store(Integer storeId, String name, String address) {
		this.storeId = storeId;
		this.name = name;
		this.address = address;
	}

	public Integer getStoreId() {
		return storeId;
	}

	public void setStoreId(Integer storeId) {
		this.storeId = storeId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@XmlTransient
	public List<Product> getProductList() {
		return productList;
	}

	public void setProductList(List<Product> productList) {
		this.productList = productList;
	}

	@XmlTransient
	public List<Purchase> getPurchaseList() {
		return purchaseList;
	}

	public void setPurchaseList(List<Purchase> purchaseList) {
		this.purchaseList = purchaseList;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (storeId != null ? storeId.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Store)) {
			return false;
		}
		Store other = (Store) object;
		if ((this.storeId == null && other.storeId != null) || (this.storeId != null && !this.storeId.equals(other.storeId))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "model.Store[ storeId=" + storeId + " ]";
	}
	
}
